package com.hui.service;

import com.hui.entity.PromotionSpace;
import com.hui.mapper.PromotionSpaceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/08/06/17:14
 * @Description:
 */
@Service("promotionSpaceService")
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
    @Autowired
    private PromotionSpaceMapper promotionSpaceMapper;

    @Override
    public List<PromotionSpace> getAllPromotionSpace() {

        return promotionSpaceMapper.getAllPromotionSpace();
    }

    @Override
    public void savePromotionSpace(PromotionSpace promotionSpace) {
        // 补全信息
        Date date = new Date();
        promotionSpace.setCreateTime(date);
        promotionSpace.setUpdateTime(date);
        promotionSpace.setSpaceKey(UUID.randomUUID().toString());
        // 调用dao层
        promotionSpaceMapper.savePromotionSpace(promotionSpace);
    }

    @Override
    public void updatePromotionSpace(PromotionSpace promotionSpace) {
        // 补全信息
        promotionSpace.setUpdateTime(new Date());
        // 调用dao层
        promotionSpaceMapper.updatePromotionSpace(promotionSpace);
    }

    @Override
    public PromotionSpace getPromotionSpaceById(Integer id) {

        return  promotionSpaceMapper.getPromotionSpaceById(id);
    }
}
